Skip to content

feat(python-sdk): add extension instrumentation#2096

Merged
pilartomas merged 3 commits into
mainfrom
feat(python-sdk)--extension-instrumentation
Feb 19, 2026
Merged

feat(python-sdk): add extension instrumentation#2096
pilartomas merged 3 commits into
mainfrom
feat(python-sdk)--extension-instrumentation

Conversation

@pilartomas
Copy link
Copy Markdown
Contributor

@pilartomas pilartomas commented Feb 13, 2026

Signed-off-by: Tomas Pilar thomas7pilar@gmail.com

Summary

This PR injects tracing into all extensions, using the same approach as A2A python SDK. It provides some additional tracing for certain extensions.

It also ensures that secrets are redacted before sending them to telemetry.

Linked Issues

closes #1975

Documentation

  • No Docs Needed:

If this PR adds new feature or changes existing. Make sure documentation is adjusted accordingly. If the docs is not needed, please explain why.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @pilartomas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the observability of the Python SDK by introducing OpenTelemetry-based instrumentation, specifically targeting the A2A extension components. It provides a robust framework for tracing functions and class methods, allowing for automatic generation of spans that capture the flow and performance of operations within agent extensions.

Highlights

  • New Telemetry Utility Module: A new telemetry.py module was introduced to centralize OpenTelemetry tracing logic, providing reusable decorators for instrumentation.
  • Function Tracing Decorator: Implemented trace_function decorator to enable flexible tracing of both synchronous and asynchronous Python functions, capturing execution details and exceptions.
  • Class Method Tracing Decorator: Developed trace_class decorator for automatically applying tracing to specified methods within a class, supporting configurable include/exclude lists and OpenTelemetry SpanKinds.
  • Extension Instrumentation: Integrated automatic tracing into BaseExtensionServer and BaseExtensionClient classes, marking their methods with SpanKind.SERVER and SpanKind.CLIENT respectively for enhanced observability of agent extensions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/base.py
    • Imported necessary OpenTelemetry tracing modules and the new trace_class decorator.
    • Applied the trace_class decorator to BaseExtensionServer to enable server-side tracing for its methods.
    • Applied the trace_class decorator to BaseExtensionClient to enable client-side tracing for its methods.
  • apps/agentstack-sdk-py/src/agentstack_sdk/util/telemetry.py
    • Added a new file containing OpenTelemetry tracing helper functions and decorators.
    • Implemented trace_function for decorating individual functions with tracing capabilities, handling both sync and async functions.
    • Implemented trace_class for decorating entire classes to automatically trace their methods based on include/exclude lists.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces OpenTelemetry-based instrumentation for extensions, which is a great addition for observability. The core of this is the new agentstack_sdk/util/telemetry.py file, which provides trace_function and trace_class decorators.

My review focuses on the correctness and robustness of these new utilities. I've identified a couple of important issues:

  • A bug in how asyncio.CancelledError is handled, which could lead to incomplete trace data.
  • An issue with tracing methods decorated with @asynccontextmanager, like lifespan, which would result in incorrect trace spans.

I've provided suggestions to fix these issues. Additionally, I've pointed out a couple of areas for improvement in code quality. Overall, this is a solid feature, and with these adjustments, it will be even more robust.

Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/base.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/util/telemetry.py
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/base.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/util/telemetry.py Outdated
@pilartomas pilartomas force-pushed the feat(python-sdk)--extension-instrumentation branch 2 times, most recently from d06c7d1 to 7f6cfa9 Compare February 16, 2026 14:58
@pilartomas
Copy link
Copy Markdown
Contributor Author

@gemini have a look

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces OpenTelemetry-based instrumentation for SDK extensions and enhances security by utilizing pydantic.SecretStr and a new SecureBaseModel for automatic redaction of sensitive data. However, a critical security vulnerability was identified where sensitive information, including tool arguments, command-line arguments, and URLs, is logged in plain text to telemetry backends. This poses a significant risk of exposing secrets, particularly due to missing redaction logic in the Approval and MCP extensions and an insufficient redaction policy in the base extension server's telemetry logging. Additionally, there are minor areas for improvement for code clarity and simplification.

Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/interactions/approval.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/services/mcp.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/base.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/a2a/extensions/interactions/approval.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/util/pydantic.py Outdated
Comment thread apps/agentstack-sdk-py/src/agentstack_sdk/util/pydantic.py Outdated
@pilartomas pilartomas marked this pull request as ready for review February 17, 2026 08:46
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Feb 17, 2026
@pilartomas pilartomas force-pushed the feat(python-sdk)--extension-instrumentation branch from ecd2b9a to a719275 Compare February 17, 2026 09:02
Signed-off-by: Tomas Pilar <thomas7pilar@gmail.com>
@pilartomas pilartomas force-pushed the feat(python-sdk)--extension-instrumentation branch from 868b5ab to 0c987e0 Compare February 19, 2026 07:32
Signed-off-by: Tomas Pilar <thomas7pilar@gmail.com>
Signed-off-by: Tomas Pilar <thomas7pilar@gmail.com>
@pilartomas pilartomas merged commit ddaf282 into main Feb 19, 2026
11 checks passed
@pilartomas pilartomas deleted the feat(python-sdk)--extension-instrumentation branch February 19, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add instrumentation to SDK extensions

1 participant